﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using HigLabo.WindowsAzure.RestService.Extensions;

namespace HigLabo.WindowsAzure.RestService.ServiceManagement
{
    public class Subscription
    {
        public enum SubscriptionStatus
        {
            Active,
            Disabled
        }
        public static readonly String ElementName = "Subscription";

        public String SubscriptionID { get; private set; }
        public String SubscriptionName { get; private set; }
        public SubscriptionStatus? Status { get; private set; }
        public String AccountAdminLiveEmailId { get; private set; }
        public String ServiceAdminLiveEmailId { get; private set; }
        public Int32 MaxCoreCount { get; private set; }
        public Int32 MaxStorageAccounts { get; private set; }
        public Int32 MaxHostedServices { get; private set; }
        public Int32 CurrentCoreCount { get; private set; }
        public Int32 CurrentHostedServices { get; private set; }
        public Int32 CurrentStorageAccounts { get; private set; }

        public Subscription(XElement xml)
        {
            if (xml == null)
            {
                throw new ArgumentNullException("xml");
            }
            /*Location*/
            this.SubscriptionID = xml.ValueOrEmpty("SubscriptionID");
            this.SubscriptionName = xml.ValueOrEmpty("SubscriptionName");
            this.Status = xml.ValueToEnum<SubscriptionStatus>("SubscriptionStatus");
            this.AccountAdminLiveEmailId = xml.ValueOrEmpty("AccountAdminLiveEmailId");
            this.ServiceAdminLiveEmailId = xml.ValueOrEmpty("ServiceAdminLiveEmailId");
            this.MaxCoreCount = xml.ValueToInt32("MaxCoreCount", 0);
            this.MaxStorageAccounts = xml.ValueToInt32("MaxStorageAccounts", 0);
            this.MaxHostedServices = xml.ValueToInt32("MaxHostedServices", 0);
            this.CurrentCoreCount = xml.ValueToInt32("CurrentCoreCount", 0);
            this.CurrentHostedServices = xml.ValueToInt32("CurrentHostedServices", 0);
            this.CurrentStorageAccounts = xml.ValueToInt32("CurrentStorageAccounts", 0);
        }
    }
}
